package com.gdwstudy.threadUse;

/**
 * @author 关道伟
 * @version 1.0
 * 通过实现接口runnable来开发线程
 */
public class Thread02 {
    public static void main(String[] args) {
        Dog dog = new Dog();
        //此时dog不能使用star方法了 怎么启动线程呢？
        Thread thread = new Thread(dog);//创建Thread对象
        // 将dog对象(要求实现了runnable接口)放入Thread
        thread.start();
    }
}

class Dog implements Runnable{//通过实现runnable接口 开发线程
    int count = 0;
    @Override
    public void run() {
        while(true){
            System.out.println("小狗汪汪叫..."+count++ +Thread.currentThread().getName());
            if(count==10){
                break;
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
